package com.eshore.norm.pojo.po.cmdb;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;

import java.util.Date;

/**
 * 基础实体
 *
 * @author zhangzy
 * @date 2021/2/5 16:55
 */
@EqualsAndHashCode
public abstract class BaseDO<E extends BaseDO<E>> implements IBaseDO<E> {
    /**
     * 主键
     */
    @ApiModelProperty(value = "主键")
    @TableId(value = "id", type = IdType.ID_WORKER)
    private Long id;

    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    @TableField(value = "create_date", fill = FieldFill.INSERT)
    private Date createDate;

    /**
     * 最后更新时间
     */
    @ApiModelProperty(value = "更新时间")
    @TableField(value = "update_date", fill = FieldFill.INSERT_UPDATE)
    private Date updateDate;

    public Long getId() {
        return id;
    }

    public E setId(Long id) {
        this.id = id;
        return self();
    }

    /**
     * this 强转 E
     *
     * @return E
     */
    private E self() {
        return (E) this;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public E setCreateDate(Date createDate) {
        this.createDate = createDate;
        return self();
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public E setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
        return self();
    }

    public E fillLatestDate() {
        Date date = new Date();
        createDate = date;
        updateDate = date;
        return self();
    }

    public E fillDate(Date date) {
        createDate = date;
        updateDate = date;
        return self();
    }
}
